<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="dateRange" label="收费时间" class="w-[350px] ml-2">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" @change="getTollCollectorData" />
        </a-form-item>
        <a-form-item name="czy" label="收费员" class="w-64 ml-2">
          <a-select v-model:value="formState.czy" mode="multiple" :max-tag-count="2" placeholder="请选择" :options="wardData" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="flex justify-end mb-2">
        <BaseExport type="视光" name="销售报表" code="000267" :search-params="{ ...formState }">导出</BaseExport>
      </div>
      <BaseTable fill bordered column-code="000267" :loading="loading" :data-source="tableData" :pagination="pagination">
        <template #bodyCell="{ column, index }">
          <template v-if="column.dataIndex == 'xh'">
            {{ index + 1 }}
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import dayjs from 'dayjs'
import SearchContainer from '@/components/SearchContainer'

const formRef = ref(null)
const wardData = ref([])
const formState = ref({
  czy: undefined,
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})

const { loading, tableData, pagination, getData } = useTable({
  url: '/optometry/ooadolescentcheck/getOoOpticaionByPayltemTypeStatistic',
  immediate: true,
  params: formState.value
})
// 收费员
const getTollCollectorData = async () => {
  const res = await post('/outp/mzdj/getTollCollectors', {
    stdate: formState.value['dateRange']?.[0],
    eddate: formState.value['dateRange']?.[1]
  })
  wardData.value = res.data.map((item) => {
    return {
      label: item?.empName,
      value: item?.empId
    }
  })
}
onMounted(() => {
  getTollCollectorData()
})
</script>
